package com.example.calculation;


import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class except extends AppCompatActivity implements View.OnClickListener {

    private EditText except_1;
    private EditText except_2;
    private TextView tv_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_except);

        tv_result = findViewById(R.id.tv_result);
        except_1 = findViewById(R.id.add_1);
        except_2 = findViewById(R.id.add_2);
        findViewById(R.id.btn).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        //将输入框的值获取出来且转成字符串形式
        String firstNum = except_1.getText().toString();
        String secondNum = except_2.getText().toString();
        //计算结果
        if(Double.parseDouble(secondNum) != 0){
            double result = Double.parseDouble(firstNum) / Double.parseDouble(secondNum);
            String show = String.valueOf(result);
            //显示在文本框中
            tv_result.setText(show);
            DaoImp imp = new DaoImp();
            imp.add(show);
        }else {
            tv_result.setText("ERROR!被除数不能为零，请重试！");
        }


    }
}